<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>网站主页</title>
</head>
<body>
	<h2>网站主页</h2>

	<h3>用户资料</h3>
	<div>
		用户姓名：<span id="userInfo"></span>
	</div>

	<h3>门户内容</h3>
	<div>
		<table id="table" border="1" cellspacing="0">
			<thead>
				<tr>
					<td style="background-color: blue;">编号</td>
					<td style="background-color: blue;">内容</td>
				</tr>
			</thead>
			<tbody>
			</tbody>
		</table>
	</div>
</body>
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
	$(function() {
		//加载主页内容
		$.get("http://127.0.0.1/api/portal/list", {}, function(result) {
			var $tableBody = $('#table tbody');
			$.each(result, function(i, n) {
				//数据添加到表格
				var row = $("<tr></tr>");
				row.append("<td>" + result[i].id + "</td>"); //id
				row.append("<td>" + result[i].name + "</td>"); //内容
				$tableBody.append(row);
			});
		});

		//加载用户资料
		$.ajax({
			url : "http://127.0.0.1:8080/api/user",
			type : "get",
			dataType : "jsonp",
			jsonp : "callback",
			success : function(json) {
			  $('#userInfo').html(JSON.stringify(json));
			},
			error : function() {
				alert('error');
			}
		});
	});
</script>
</html>